# 6_2 屏幕使用：分组与显示文本
# https://learn.adafruit.com/circuitpython-display-support-using-displayio
# https://learn.adafruit.com/circuitpython-display-support-using-displayio/ui-quickstart
# https://learn.adafruit.com/custom-fonts-for-pyportal-circuitpython-display

'''
2. 分组与显示文本
'''
import time
import board
import displayio
import terminalio
from adafruit_display_text import label

# 1. 屏幕基础配置
display = board.DISPLAY

# 2. 显示文本
text = "Hello World!"
text_area = label.Label(terminalio.FONT, text=text, color=0xFF0000, x=20, y=20)
text_group = displayio.Group(
    scale=2,
    x=0,
    y=0,
)
text_group.append(text_area)  # Subgroup for text scaling
display.show(text_group)

# 修改文本
for i in range(10):
    text_area.text = "count=%d" % i
    time.sleep(0.5)

# 隐藏文本
for i in range(10):
    text_area.hidden = not text_area.hidden
    text_area.text = "hide text" if text_area.hidden else "show text"
    time.sleep(0.5)
